<?php
use yii\bootstrap\ActiveForm;
use common\helps\tools;
?>
<link rel="stylesheet" href="../static/dist/css/AdminLTE.min.css" type="text/css">
<link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="../static/plugins/datatables/jquery.dataTables.css" type="text/css">
<link rel="stylesheet" href="../static/css/admin.css" type="text/css">
<link rel="stylesheet" href="../static/jBox/Skins/Metro/jbox.css" type="text/css">
<link rel="stylesheet" type="text/css" href="../static/app/goods-keyword/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../static/app/goods-keyword/css/jquery.dropdown.css">
<style>
.dataTables_length {
	margin-top: 10px;
}

.dataTable>tbody>tr>td {
	vertical-align: middle;
	font-size: 0.8em;
	padding: 8px 18px;
}

.dataTable>thead>tr>th {
	vertical-align: middle;
	font-size: 0.8em;
}

.source_type_class {
	min-height: 20px;
	padding-left: 20px;
	margin-bottom: 0;
	font-weight: 400;
	cursor: pointer;
}
.form-left{
    border-right: 1px solid #dddddd;
}

.examine-content{
    width: 1000px;
	margin-left:-300px;
}
.examine-content .input-group .form-control{
    margin-bottom: 20px;
    height: 30px ;
    line-height: 30px;
}
.examine-content button{
    margin: 10px;
}
label{
	text-align: right;
}
</style>
<div class="tabs-panel">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<div class="box-body">
					<div class="modal-body">
                        <?php
                        $form = ActiveForm::begin([
                            'id' => 'add_main_goods_form',
                            'action' => ['/goods/add-main-goods']
                        ]);
                        ?>
                        <div class="box-body">
                        	<div class="col-md-12">
                        		<div class="col-md-12">
            						<label class="col-sm-2 control-label"><span class="text-danger">* </span>商品中文名称</label>
            						<div class="col-sm-4">
            							<input value="" type="text" class="form-control" name="goods_name_cn" id="add_goods_name_cn" placeholder="商品中文名称">
            						</div>
            						<label class="col-sm-2 control-label">商品其他名称</label>
            						<div class="col-sm-4">
            							<input value="" type="text" class="form-control" name="goods_name_other" id="add_goods_name_other" placeholder="商品其他名称">
            						</div>
            					</div><br/><br/><br/>
            					<div class="col-md-12">
            						<label class="col-sm-2 control-label"><span class="text-danger">* </span>商品分类</label>
            						<div class="col-sm-4">
                						<select id="add_category_step1" name="category_step1" class="form-control">
                							<option value="0">选择商品一级分类</option>
                                            <?php foreach($category_list as $value){?>
                                                <option value="<?= $value['id']?>" <?=(tools::arrayHasValue($result,'category_step1') && $result['category_step1'] == $value['id'] ? 'selected' : '')?>><?= $value['category_name']?></option>
                                            <?php }?>
                                        </select>
            						</div>
            						<label class="col-sm-2 control-label"><span class="text-danger">* </span>商品二级分类</label>
            						<div class="col-sm-4">
                                        <select id="add_category_step2" name="category_step2" class="form-control">
                							<option value="0">选择商品二级分类</option>
                						</select>
            						</div>
            					</div><br/><br/><br/>
            					<div class="col-md-12">
            						<label class="col-sm-2 control-label"><span class="text-danger">* </span>商品品类</label>
            						<div class="col-sm-4">
            							<select id="add_tag_id" name="tag_id" class="form-control">
                							<option value="0">选择商品品类</option>
                						</select>
            						</div>
            						<label class="col-sm-2 control-label"><span class="text-danger">* </span>商品品牌</label>
            						<div class="col-sm-4">
            							<select id="add_brand_id" name="brand_id" class="form-control">
                							<option value="0">选择商品品牌</option>
                						</select>
            						</div>
            					</div><br/><br/><br/>
            					<div class="col-md-12">
            						<label class="col-sm-2 control-label"><span class="text-danger">* </span>商品列表图</label>
            						<div class="col-sm-4">
                						<button type="button" class="btn btn-success depart-modal upload-img-btn-main-pic" style="width: 120px;">上传商品列表图</button>
                						<button style="display: none;" data-img="" type="button" class="btn btn-success depart-modal show-img-btn-main-pic" style="width: 110px;">查看图片</button>
                						<input name="goods_main_pic" value="" id="add_goods_main_pic" type="hidden">
            						</div>
            						<!-- mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  start -->
            						<label class="col-sm-2 control-label">系列号</label>
            						<div class="col-sm-4">
            							<input type="text" value="" class="form-control" name="series" id="series" placeholder="系列号">
            						</div>
            						<!-- mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  end -->
            					</div><br/><br/><br/>
            					<div class="col-md-12">
            						<label class="col-sm-2 control-label">图片title</label>
            						<div class="col-sm-4">
            							<input type="text" value="" class="form-control" name="goods_pic_title" id="add_goods_pic_title" placeholder="图片title">
            						</div>
            						<label class="col-sm-2 control-label">图片alt</label>
            						<div class="col-sm-4">
            							<input type="text" value="" class="form-control" name="goods_pic_alt" id="add_goods_pic_alt" placeholder="图片alt">
            						</div>
            					</div><br/><br/><br/>
            					<div class="col-md-12" style="margin-bottom: 10px;">
            						<label class="col-sm-2 control-label">关键字</label>
            						<div class="col-sm-10">
                						<button type="button" class="btn btn-success depart-modal" id="add_input_keyword" style="width: 100px;">添加</button>
                						<table class="table table-hover" id="input_table_keyword">
                							<tr>
                								<th>关键字</th>
                								<th>操作</th>
                							</tr>
                						</table>
            						</div>
            					</div><br/><br/><br/>
            					<div class="col-md-12" style="margin-bottom: 10px;">
            						<label class="col-sm-2 control-label">导航分类展示</label>
            						<div class="col-sm-10" id="navigation_identification">
            							<?php 
            							$navigation_identification_html = '';
            							if(is_array($navigation_identification_list) && count($navigation_identification_list) > 0){
            							    foreach ($navigation_identification_list as $nav){
            							        $son = tools::arrayHasValue($nav,'son') ? $nav['son'] : [];
            							        $navigation_identification_html .= '<div class="col-md-12">';
            							        $navigation_identification_html .= '<div style="float:left;width:100px">';
            							        $navigation_identification_html .= '<input style="width:18px;height:18px;" '.(in_array($nav['id'], $goods_navigation_identification_id) ? 'checked' : '').' name="navigation_identification_id" type="radio" value="'.$nav['id'].'"> '.$nav['name'];
            							        $navigation_identification_html .= '</div>';
            							        if(count($son) > 0){
            							            $navigation_identification_html .= '<div class="second_level '.(in_array($nav['id'],$goods_navigation_identification_id) ? '' : 'hide').'">';
            							            forEach($son as $son_val){
            							                $navigation_identification_html .= '<div style="float:left;width:120px;">';
            							                $navigation_identification_html .= '<input style="width:18px;height:18px;" '.(in_array($son_val['id'],$goods_navigation_identification_id) ? 'checked' : '').' name="navigation_identification_id" type="checkbox" value="'.$son_val['id'].'"> '.$son_val['name'];
            							                $navigation_identification_html .= '</div>';
            							            }
            							            $navigation_identification_html .= '</div>';
            							        }
            							        $navigation_identification_html .= '</div>';
            							    }
            							}
            							echo $navigation_identification_html;
            							?>
            						</div>
            					</div><br/><br/><br/>
            					<div class="col-md-12 hide" style="margin-bottom: 10px;">
            						<label class="col-sm-2 control-label">商品搭配</label>
            						<div class="col-sm-10">
                						<button type="button" class="btn btn-success depart-modal" id="add_input_sku" style="width: 100px;">添加</button>
                						<table class="table table-hover" id="input_table_sku">
                							<tr>
                								<th>物料号</th>
                								<th>操作</th>
                							</tr>
                							<?php 
                							if (is_array($relation_list) && count($relation_list) > 0)foreach ($relation_list as $relation_val){
                							?>
                							<tr>
                								<td><input name="sku[]" value="<?=$relation_val['sku']?>" class="form-control"></td>
                								<td><a href="javascript:;" class="up_input_table_tr">上移</a> <a href="javascript:;" class="down_input_table_tr">下移</a> <a class="del_input_table_tr" href="javascript:;">删除</a></td>
                							</tr>
                							<?php }?>
                						</table>
            						</div>
            					</div><br/><br/><br/>
            					<div class="col-md-12" style="margin-bottom: 30px;">
            						<label class="col-sm-2 control-label"><span class="text-danger">* </span>价格单位</label>
            						<div class="col-sm-4">
                						<select id="add_unit" name="unit" class="form-control">
                							<option value="$">$</option>
											<option value="¥">¥</option>
                						</select>
            						</div>
            						<label class="col-sm-2 control-label">排序</label>
            						<div class="col-sm-4">
            							<input type="text" style="width: 50%;" class="form-control" name="sort" id="add_sort" placeholder="排序">
            						</div>
            					</div>
            					
            					<div class="col-md-12" style="margin-bottom: 30px;">
            						<label class="col-sm-2 control-label">商品详情页价格描述</label>
            						<div class="col-sm-4">
            							<!-- <input type="checkbox" style="width:20px;height:20px;" name="hidden_price" id="add_hidden_price"> -->
            							<select id="add_hidden_price" name="hidden_price" class="form-control">
                							<option value="0">请选择</option>
                							<option value="1">价格展示文字：请咨询客服</option>
                							<option value="2">市场价后加“起”</option>
                							<option value="3">销售价后加“起”</option>
                							<option value="4">市场价和销售价后都加“起”</option>
                						</select>
            						</div>
            						<!-- add by lizenan 20180129 【商城需求】商品详情页增加查看同品牌商品的按钮   488  start -->
            						<label class="col-sm-2 control-label"></label>
            						<div class="col-sm-4" style="position: relative;">
										<!--mod by FDG367 488 【商城需求】商品详情页增加查看同品牌商品的按钮 start-->
            							<input value="" style="width:20px;height:20px; position: absolute;top:-4px;" type="checkbox" name="see_more_product" id="see_more_product">
            							<label style="padding-left: 30px"> 商品详情页展示查看更多同品牌商品</label>
										<!--mod by FDG367 488 【商城需求】商品详情页增加查看同品牌商品的按钮 end-->
            						</div>
            						<!-- add by lizenan 20180129 【商城需求】商品详情页增加查看同品牌商品的按钮   488  end -->
            					</div>
            					
            					 <div class="col-md-12" style="margin-bottom: 30px;">
            						<label class="col-sm-2 control-label"><span class="text-danger">* </span>状态</label>
            						<div class="col-sm-4">
                						<select id="use_flg" name="use_flg" class="form-control">
                							<option value="1">上架</option>
                							<option value="0">下架</option>
                							<option value="2">上架已售罄</option>
                						</select>
            						</div>
            						<!-- <label for="exampleInputEmail1" class="col-sm-2 control-label">商品标识</label>
            						<div class="col-sm-4">
                						<select id="goods_identification" name="goods_identification" class="form-control">
                							<option value="">请选择</option>
                							<?php 
                							//if (is_array($goods_identification) && count($goods_identification))foreach ($goods_identification as $identification_val){
                							?>
                							<option value="<?php //$identification_val['id']?>"><?php //$identification_val['name']?></option>
                							<?php 
                							//}
                							?>
                						</select>
            						</div> -->
            					</div>
            					<div class="col-md-12" style="margin-bottom: 30px;">
            						<label class="col-sm-2 control-label">商品中文描述</label>
            						<div class="col-sm-10">
            							<textarea class="form-control xheditor" name="brief_cn" id="add_brief_cn" placeholder="" style="width: 80%;height:200px"></textarea>
            						</div>
            					</div>
            					<div class="col-md-12">
            						<label class="col-sm-2 control-label">商品其他描述</label>
            						<div class="col-sm-10">
            							<textarea class="form-control xheditor" name="brief_other" id="add_brief_other" placeholder="" style="width: 80%;height:200px"></textarea>
            						</div>
            					</div>
                        	</div>
        				</div>
        
        				<input name="add_main_id" id="add_main_id" type="hidden"> <input name="add_main_goods_id" id="add_main_goods_id" type="hidden">
                        <?php ActiveForm::end(); ?>
                    </div>
        
        			<div style="display: none">
                        <?php $form = ActiveForm::begin(['id'=>'upload_goods_main_pic','action'=>'/common/img-upload'],['options' => ['enctype' => 'multipart/form-data']]) ?>
                        <?= $form->field($model, 'img_url')->fileInput(['class' => 'upload_file_goods_main_pic']) ?>
                        <?php ActiveForm::end() ?>
                    </div>
        
        			<div class="modal-footer">
        				<button type="button" class="btn btn-default" onclick="history.back();">返回
        				</button>
        				<a type="button" class="btn btn-primary ajax_post_add_goods"> 提交 </a>
        			</div>
				</div>
			</div>
		</div>
	</div>
</div>
<input id="old_id" value="" type="hidden"/>
<input name="class_len" id="class_len" value="0" type="hidden"/>
<input name="class_len_2" id="class_len_2" value="0" type="hidden"/>
<input type="hidden" name="imageBathUrl" id="imageBathUrl" value="<?php echo Yii::$app->params['imageBathUrl'] . '/' ?>">
<script type="text/javascript" src="../static/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="../static/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../static/plugins/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../static/jBox/jquery.jBox-2.3.min.js"></script>
<script type="text/javascript" src="../static/jBox/i18n/jquery.jBox-zh-CN.js"></script>
<script type="text/javascript" src="/static/plugins/xheditor/xheditor-1.2.2.min.js"></script>
<script type="text/javascript" src="/static/plugins/xheditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="../static/plugins/jquery.form.js"></script>
<script type="text/javascript" src="../static/plugins/layer/layer.js"></script>
<script type="text/javascript" src="../static/app/goods-keyword/js/jquery.dropdown.js"></script>
<script type="text/javascript" src="../static/app/goods-keyword/js/mock.js"></script>
<!-- 自定义js -->
<script type="text/javascript" src="/static/app/global.js?version=<?=Yii::$app->params['version']?>"></script>
<script type="text/javascript" src="../static/app/goods/detail.js?version=<?=Yii::$app->params['version']?>"></script>
<script>
	//mod by lizenan 20180119 【后台需求】关键词维护改进   430  start
    //var keyword_data = <?php //(is_array($keyword) ? json_encode($keyword) : '')?>;
	//mod by lizenan 20180119 【后台需求】关键词维护改进   430  end
    //下拉框选择分类，品牌，品类
    var category_child_list = <?=(is_array($category_child_list) ? json_encode($category_child_list) : '')?>;
    //var category_child_list = jQuery.parseJSON(category_child_string);

    var brand_list = <?=(is_array($brand_list) ? json_encode($brand_list) : '')?>;
    //var brand_list = jQuery.parseJSON(brand_string);

    var tag_list = <?=(is_array($tag_list) ? json_encode($tag_list) : '')?>;
    //var tag_list = jQuery.parseJSON(tag_string);
    var navigation_identification_list = <?=(is_array($navigation_identification_list) ? json_encode($navigation_identification_list) : '')?>;
    var goods_navigation_identification_id = <?=(is_array($goods_navigation_identification_id) ? json_encode($goods_navigation_identification_id) : '')?>;
    <?php 
    if (is_array($result) && count($result) > 0){
    ?>
    var data =  <?=json_encode($result)?>;
    setValue(data);
    <?php 
    }
    ?>
    function setValue(data){
        $('#add_goods_name_cn').val(data['goods_name_cn']);
        $('#add_goods_name_other').val(data['goods_name_other']);
        $('#add_category_step1').val(data['category_step1']);
        $('#use_flg').val(data['use_flg']);
        if(data['category_step1'] != 0 && data['category_step1'] != null && data['category_step1'] != undefined){
            var category_child = category_child_list[data['category_step1']];
            $('#add_category_step2').empty();
            $('#add_category_step2').append('<option value="0">选择商品二级分类</option>');
            if(typeof category_child === 'object'){
                for(var i=0;i<category_child.length;i++){
                        $('#add_category_step2').append('<option value="'+category_child[i]['id']+'">'+category_child[i]['category_name']+'</option>');
                }
            }
            $('#add_category_step2').val(data['category_step2']);
        }
        if(data['keyword_name'] != '' && data['keyword_name'] != null && data['keyword_name'] != undefined){
        	var akeyword = [];
        	akeyword = data['keyword_name'].split(',');
            for (i=0;i<akeyword.length ;i++ ){
            	var html = '';
            	var class_len = $('#class_len').val();
                var div_class = 'dropdown-sin-'+class_len;
        		html += '<tr><td>';
        		//mod by lizenan 20180119 【后台需求】关键词维护改进   430  start
//             	html += '<div class="'+div_class+'">';
//            	 	html += '<select style="display:none" name="keyword[]" placeholder="请选择">';
//            	 	if(keyword_data.length > 0){
//                 	keyword_data.forEach(function(data,index){
//                 		html += '<option value="'+data.name+'" '+(data.name == akeyword[i] ? 'selected' : '')+'>'+data.name+'</option>';
//                     });
//            	 	}
//             	html += '</select>';
//             	html += '</div>';
        		html += '<input value="'+akeyword[i]+'" class="form-control" name="keyword[]" type="text">';
            	html += '</td>';
            	html += '<td><a class="del_input_table_tr" href="javascript:;">删除</a></td> </tr>';
//             	class_len++;
//                 $('#class_len').val(class_len);
                $('#input_table_keyword').append(html);
//                 $('.'+div_class).dropdown({
//                   readOnly: true,
//                   input: '<input type="text" maxLength="20" placeholder="请输入搜索">'
//                 });
				//mod by lizenan 20180119 【后台需求】关键词维护改进   430  end
        	}
        }
        /*商品导航标识*/
        var navigation_identification_html = '';
        if(navigation_identification_list.length > 0){
        	navigation_identification_list.forEach(function(e){
            	var son = e.son ? e.son : [];
        		navigation_identification_html += '<div class="col-md-12">';
        		navigation_identification_html += '<div style="float:left;width:100px">';
        		navigation_identification_html += '<input style="width:18px;height:18px;" '+($.inArray(e.id,goods_navigation_identification_id) >= 0 ? 'checked' : '')+' name="navigation_identification_id" type="radio" value="'+e.id+'">'+e.name;
        		navigation_identification_html += '</div>';
				if(son.length > 0){
					navigation_identification_html += '<div class="second_level '+($.inArray(e.id,goods_navigation_identification_id) >= 0 ? '' : 'hide')+'">';
					son.forEach(function(i){
						navigation_identification_html += '<div style="float:left;width:120px;">';
						navigation_identification_html += '<input style="width:18px;height:18px;" '+($.inArray(i.id,goods_navigation_identification_id) >= 0 ? 'checked' : '')+' name="navigation_identification_id" type="checkbox" value="'+i.id+'"> '+i.name;
						navigation_identification_html += '</div>';
					});
					navigation_identification_html += '</div>';
				}
        		navigation_identification_html += '</div>';
           	});
        }
        $('#navigation_identification').html(navigation_identification_html);
        if(data['category_step2'] != 0 && data['category_step2'] != null && data['category_step2'] != undefined){
            var tag = tag_list[data['category_step2']];
            $('#add_tag_id').empty();
            $('#add_tag_id').append('<option value="0">选择商品品类</option>');
            if(typeof tag === 'object'){
                for(var i=0;i<tag.length;i++){
                    $('#add_tag_id').append('<option value="'+tag[i]['tag_id']+'">'+tag[i]['tag_name']+'</option>');
                }
            }
            $('#add_tag_id').val(data['tag_id']);
        }
        if(data['category_step1'] != 0 && data['category_step1'] != null && data['category_step1'] != undefined){
            var brand = brand_list[data['category_step1']];
            $('#add_brand_id').empty();
            $('#add_brand_id').append('<option value="0">选择商品品牌</option>');
            if(typeof brand === 'object'){
            	//mod by lizenan 20180118 【后台管理】商品分类中选择品牌逻辑调整  过滤商品详情页品牌重复问题   468  start
            	//新增行 468
                var brand_id_ed = [];
                for(var i=0;i<brand.length;i++){
                	//新增if判断 468
                    if($.inArray(brand[i]['brand_id'],brand_id_ed) != -1){
                    	continue;
                    }
                    $('#add_brand_id').append('<option value="'+brand[i]['brand_id']+'">'+brand[i]['brand_name']+'</option>');
                    //新增行 468
                    brand_id_ed.push(brand[i]['brand_id']);
                }
                //mod by lizenan 20180118 【后台管理】商品分类中选择品牌逻辑调整  过滤商品详情页品牌重复问题   468  end
            }
            $('#add_brand_id').val(data['brand_id']);
        }
        $('#add_unit').val(data['unit']);
        $('#add_sort').val(data['sort']);
        var hidden_price = data['hidden_price'];
        $('#add_hidden_price').val(hidden_price);
        var see_more_product = data['see_more_product'];
        $('#see_more_product').prop('checked',see_more_product == '1' ? true : false);
        $('#goods_identification').val(data['identification_id']);
        $('#add_main_id').val(data['id']);
        $('#add_main_goods_id').val(data['main_goods_id']);
        if(data['goods_main_pic'] != 0 && data['goods_main_pic'] != null && data['goods_main_pic'] != undefined){
            $('#add_goods_main_pic').val(data['goods_main_pic']);
            $('.show-img-btn-main-pic').attr('data-img',data['goods_main_pic']);
            $('.show-img-btn-main-pic').show();
        }
        //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  start
        $('#series').val(data['series']);
        //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  end
        $('#add_goods_pic_title').val(data['goods_pic_title']);
        $('#add_goods_pic_alt').val(data['goods_pic_alt']);
        $('#add_brief_cn').val(data['brief_cn']);
        $('#add_brief_other').val(data['brief_other']);
    }
</script>